import {
  request
} from './request'

export function getRolesList() {
  return request({
    url: 'roles',
  })
}

export function addRoleInfo(addForm) {
  return request({
    url: 'roles',
    method: 'post',
    data: addForm
  })
}

export function getRoleInfoById(id) {
  return request({
    url: 'roles/' + id,
    method: 'get',
  })
}

export function editRoleInfoById(editRoleForm) {
  const {
    roleId,
    roleName,
    roleDesc
  } = editRoleForm
  return request({
    url: 'roles/' + roleId,
    method: 'put',
    data: {
      roleName,
      roleDesc
    }
  })
}

export function removeRoleInfoById(id) {
  return request({
    url: 'roles/' + id,
    method: 'delete',
  })
}

export function allotRoleById(userId, rid) {
  return request({
    url: `users/${userId}/role`,
    method: 'put',
    data: {
      rid
    }
  })
}